<template>
  <view class="container">
    <!-- 用户信息 -->
    <view v-if="isAuthInfo" class="userinfo">
      <view class="userinfo-con">
        <view class="userinfo-avatar">
          <img-show :src="userInfo.avatar" :defaultImgType="!!userInfo.avatar" />
        </view>
        <view class="userinfo-name">
          <view>{{ userInfo.realname ? userInfo.realname : "用户昵称" }}</view>
        </view>
      </view>
    </view>

    <view v-if="!isAuthInfo" class="userinfo-none">
      <view class="default-pic" @tap="toLogin">
        <image src="@/static/images/icon/head04.png" />
      </view>
      <view class="none-login" @tap="toLogin">
        <button class="unlogin">
          未登录
        </button>
        <button class="click-login">
          点击登录账号
        </button>
      </view>
    </view>
    <!-- end 用户信息 -->

    <view class="list-cont">
      <!-- 列表项 -->
      <view class="my-menu">
        <view class="memu-item" @tap="goPage()">
          <view class="i-name">
            <image src="@/static/images/icon/promotion.png" />
            <text>预约记录</text>
          </view>
          <view class="arrowhead" />
        </view>
        <view class="memu-item" @tap="goPage('/pages/informationFill/informationFill')">
          <view class="i-name">
            <image src="@/static/images/icon/getCoupon.png" />
            <text>信息填报</text>
          </view>
          <view class="arrowhead" />
        </view>
        <view class="memu-item" @tap="goPage()">
          <view class="i-name">
            <image src="@/static/images/icon/myCoupon.png" />
            <text>报告查询</text>
          </view>
          <view class="arrowhead" />
        </view>
        <view class="memu-item" @tap="goPage()">
          <view class="i-name">
            <image src="@/static/images/icon/myAddr.png" />
            <text>设置</text>
          </view>
          <view class="arrowhead" />
        </view>
      </view>
      <!--end 列表项 -->

      <!-- <view v-if="isAuthInfo" class="log-out" @tap="logout">
        <view class="log-out-n">
          <text>退出登录</text>
        </view>
      </view> -->
    </view>
  </view>
</template>

<script setup>
  const isAuthInfo = ref(false)
  const userInfo = ref('')

  /**
   * 生命周期函数--监听页面显示
   */
  onShow(() => {
    userInfo.value = uni.getStorageSync('loginUserInfo');
    isAuthInfo.value = !util.judgeNull(userInfo.value);
  })

  const goPage = (page) => {
    // #ifdef MP-WEIXIN
    if (util.judgeNull(uni.getStorageSync('Token'))) {
      http.noTokenShowModal('请先登录', 'pages/index/index');
      return;
    }
    // #endif
    let userInfo = uni.getStorageSync('loginUserInfo') || {};
    if ((util.judgeNull(userInfo.agreeAgreementPolicy) || userInfo.agreeAgreementPolicy == '0')) {
      uni.reLaunch({
        url: '/pages/index/index', // 需要重新打开的页面路径
      });
      return;
    }
    uni.navigateTo({
      url: page
    })
  }

  /**
   * 去登陆
   */
  const toLogin = () => {
    // #ifdef MP-WEIXIN
    // http.noTokenShowModal('请进行登录', 'pages/user/user')
    http.noTokenShowModal('请进行登录', 'pages/index/index');
    // #endif
    // #ifdef APP-PLUS
    uni.navigateTo({
      url: '/pages/accountLogin/accountLogin'
    });
    // #endif
  }

  /**
   * 退出登录
   */
  const logout = () => {
    uni.showLoading({
      title: '加载中'
    });
    http.post('/logOut').then(() => {
      util.removeTabBadge();
      uni.removeStorageSync('loginUserInfo');
      uni.removeStorageSync('token');
      uni.showToast({
        title: '退出成功',
        icon: 'none'
      });
      setTimeout(() => {
        uni.switchTab({
          url: '/pages/index/index'
        });
      }, 1000)
    }).catch(err => {
      console.log('登出失败 ==> ', err);
      uni.hideLoading();
    })
  }
</script>

<style scoped lang="scss">
  @use './user.scss';
</style>
